<template>
  <el-card class="weather-panel">
    <template #header>
      <div class="panel-header">
        <el-icon><Sunny /></el-icon>
        <span>天气预报</span>
      </div>
    </template>
    
    <!-- 今日天气 -->
    <div class="today-weather">
      <div class="weather-main">
        <div class="weather-icon">
          <el-icon :size="48"><Sunny /></el-icon>
        </div>
        <div class="weather-info">
          <div class="temperature">23°C</div>
          <div class="description">晴朗</div>
        </div>
      </div>
      <div class="weather-details">
        <div class="detail-item">
          <el-icon><Umbrella /></el-icon>
          <span>湿度: 65%</span>
        </div>
        <div class="detail-item">
          <el-icon><WindPower /></el-icon>
          <span>风速: 3级</span>
        </div>
      </div>
    </div>

    <!-- 未来天气预报 -->
    <div class="forecast-list">
      <div v-for="(item, index) in weatherForecast" :key="index" class="forecast-item">
        <span class="day">{{item.day}}</span>
        <el-icon><component :is="item.icon" /></el-icon>
        <span class="temp">{{item.temp}}°C</span>
      </div>
    </div>

    <!-- 关键气象指标图表 -->
    <div class="weather-chart" ref="weatherChartRef"></div>
  </el-card>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'
import { Sunny, Cloudy, Lightning, Umbrella, WindPower } from '@element-plus/icons-vue'

const weatherForecast = ref([
  { day: '周一', icon: 'Sunny', temp: 23 },
  { day: '周二', icon: 'Cloudy', temp: 22 },
  { day: '周三', icon: 'Lightning', temp: 20 },
  { day: '周四', icon: 'Sunny', temp: 24 },
  { day: '周五', icon: 'Cloudy', temp: 21 }
])

const weatherChartRef = ref<HTMLElement>()

onMounted(() => {
  if (weatherChartRef.value) {
    const chart = echarts.init(weatherChartRef.value)
    chart.setOption({
      title: {
        text: '24小时气象趋势',
        textStyle: {
          color: '#7fdbff',
          fontSize: 14
        }
      },
      tooltip: {
        trigger: 'axis'
      },
      grid: {
        top: 40,
        left: 40,
        right: 20,
        bottom: 20
      },
      xAxis: {
        type: 'category',
        data: ['00:00', '06:00', '12:00', '18:00', '24:00'],
        axisLine: {
          lineStyle: {
            color: '#7fdbff'
          }
        }
      },
      yAxis: {
        type: 'value',
        axisLine: {
          lineStyle: {
            color: '#7fdbff'
          }
        },
        splitLine: {
          lineStyle: {
            color: 'rgba(127,219,255,0.1)'
          }
        }
      },
      series: [
        {
          name: '温度',
          type: 'line',
          smooth: true,
          data: [20, 22, 25, 23, 21],
          itemStyle: {
            color: '#ffa940'
          }
        },
        {
          name: '湿度',
          type: 'line',
          smooth: true,
          data: [60, 62, 58, 65, 63],
          itemStyle: {
            color: '#1890ff'
          }
        }
      ]
    })
  }
})
</script>

<style scoped lang="scss">
.weather-panel {
  background: rgba(0,21,41,0.6);
  border: 1px solid rgba(0,255,255,0.1);
  margin-bottom: 16px;

  :deep(.el-card__header) {
    border-bottom: 1px solid rgba(0,255,255,0.1);
    padding: 12px 16px;
  }

  .panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #7fdbff;
  }

  .today-weather {
    padding: 16px;
    
    .weather-main {
      display: flex;
      align-items: center;
      gap: 16px;
      margin-bottom: 16px;

      .weather-icon {
        color: #ffa940;
      }

      .weather-info {
        .temperature {
          font-size: 32px;
          color: #00e4ff;
          font-weight: 500;
        }

        .description {
          color: #7fdbff;
        }
      }
    }

    .weather-details {
      display: flex;
      justify-content: space-around;

      .detail-item {
        display: flex;
        align-items: center;
        gap: 8px;
        color: #7fdbff;
      }
    }
  }

  .forecast-list {
    display: flex;
    justify-content: space-between;
    padding: 16px;
    border-top: 1px solid rgba(0,255,255,0.1);

    .forecast-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 8px;
      color: #7fdbff;

      .day {
        font-size: 12px;
      }

      .temp {
        color: #00e4ff;
      }
    }
  }

  .weather-chart {
    height: 200px;
    margin-top: 16px;
  }
}
</style> 